import * as types from './../constants/ActionTypes';
import {
    api
}
from './../config/Apis';

/*
 * 用户登录
 ================================================================*/
export function login({phone, password} = {}) {
    return (dispatch) => {
        let payload = { 
            login_status : 0,
            message : '' ,
            phone : phone, 
            password : password
        };
        
        dispatch({
            payload , 
            type: [types.LOGIN, types.LOGIN_SUCCESS, types.LOGIN_FAILURE],
            meta: {
                fetch: [
                    `members/login`, {
                        method: "POST",
                        body: `phone=${phone}&password=${password}`
                    }
                ]
            }
        });
    };
}

/*
 * 用户退出登录
 ================================================================*/
export function logout() {
    return (dispatch) => {
        let payload = { 
            logout_status : 0,
            message : ''
        };
        
        dispatch({
            payload , 
            type: [types.LOGOUT, types.LOGOUT_SUCCESS, types.LOGOUT_FAILURE],
            meta: {
                fetch: [
                    `members/logout`, {
                        method: "GET"
                    }
                ]
            }
        });
    };
}

/*
 * 资金账号绑定
 ================================================================*/
export function bind({account, password, ticket} = {}) {
    return (dispatch) => {
        let payload = { 
            bind_status : 0, 
            message : '',
            account : account,
            ticket : ticket
        };
        
        dispatch({
            type: [types.BIND, types.BIND_SUCCESS, types.BIND_FAILURE],
            meta: {
                fetch: [
                    `member/binding`, {
                        method: "POST",
                        body: `account=${account}&password=${password}&ticket=${ticket}`
                    }
                ]
            }
        });
    };
}

